package com.byq.mm.application.cluster.client;

import java.util.ArrayList;


import com.byq.mm.abstractx.device.Device;
import com.byq.mm.abstractx.engine.CoreEnvironment;
import com.byq.mm.cluster.provider.SimpleSensorProvider;
import com.byq.mm.foundation.cluster.client.BasicClusterClient;
import com.byq.mm.foundation.cluster.datatype.AttributeValue;
import com.byq.mm.foundation.cluster.datatype.DoubleRangeValue;
import com.byq.mm.foundation.cluster.datatype.DoubleValue;
import com.byq.mm.foundation.cluster.datatype.StringValue;

public class SimpleSensorClient extends BasicClusterClient {

	public SimpleSensorClient(String cluster, Device device, CoreEnvironment e) {
		super(cluster, device, e);
		
	}
	public DoubleValue getValue(){
		return (DoubleValue)getAttributeValue(SimpleSensorProvider.Define.Attributes.VALUE);
	}
	public void readValue() {
		readAttribute(SimpleSensorProvider.Define.Attributes.VALUE);

	}
	public DoubleRangeValue getRange(){
		return (DoubleRangeValue)getAttributeValue(SimpleSensorProvider.Define.Attributes.RANGE);
	}
	public void readRange() {
		readAttribute(SimpleSensorProvider.Define.Attributes.RANGE);

	}
	public StringValue getUnit(){
		return (StringValue)getAttributeValue(SimpleSensorProvider.Define.Attributes.UNIT);
	}
	public void readUnit() {
		readAttribute(SimpleSensorProvider.Define.Attributes.UNIT);

	}
	@Override
	protected Class<? extends AttributeValue> getAttributeType(String attributeName) {
		if(attributeName.equals(SimpleSensorProvider.Define.Attributes.VALUE))
			return DoubleValue.class;
		if(attributeName.equals(SimpleSensorProvider.Define.Attributes.RANGE))
			return DoubleRangeValue.class;
		return null;
	}
	public void subscribe() {
		subscribe(SimpleSensorProvider.Define.Attributes.VALUE);

	}
	public void unsubscribe() {
		unsubscribe(SimpleSensorProvider.Define.Attributes.VALUE);
	}
	public boolean isSubscribed() {
		return subscribed.get(SimpleSensorProvider.Define.Attributes.VALUE);
	}
	public void readSubscribe() {
		readSubscribe(SimpleSensorProvider.Define.Attributes.VALUE);
	}
	@Override
	protected void init() {
		attributes.put(SimpleSensorProvider.Define.Attributes.VALUE,new DoubleValue(0));
		subscribed.put(SimpleSensorProvider.Define.Attributes.VALUE,  false);
		attributes.put(SimpleSensorProvider.Define.Attributes.RANGE,  new DoubleRangeValue(0,50));
	}



}
